//
//  TopCollectionViewCell.m
//  GoTraveling
//
//  Created by 陈金山 on 15/12/24.
//  Copyright © 2015年 开发华佗. All rights reserved.
//

#import "TopCollectionViewCell.h"
#import "UIImageView+WebCache.h"
#import "ZHFImageView.h"

@interface TopCollectionViewCell ()

@property (nonatomic, retain) UIImageView *headImageView;

@property (nonatomic, retain) UILabel *title;

@property (nonatomic, retain) UIImageView *userImageView;

@property (nonatomic, retain) UILabel *userName;

@end

@implementation TopCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createSubViews];
        self.contentView.layer.cornerRadius = 5;
        self.contentView.layer.masksToBounds = YES;
    }
    return self;
}

- (void)createSubViews {
    
    ZHFImageView *occupyImage = [[ZHFImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height * 3 / 5)];
    occupyImage.layer.cornerRadius = 5;
    occupyImage.layer.masksToBounds = YES;
    [self.contentView addSubview:occupyImage];
    
#pragma mark headImageView
    self.headImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.contentView.frame.size.width, self.contentView.frame.size.height * 3 / 5)];
    self.headImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.headImageView.layer.cornerRadius = 5;
    self.headImageView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.headImageView];
#pragma mark title
    self.title = [[UILabel alloc] initWithFrame:CGRectMake(10, self.headImageView.frame.size.height + 10, self.contentView.frame.size.width - 20, self.contentView.frame.size.height / 5)];
    self.title.numberOfLines = 2;
    self.title.font = [UIFont systemFontOfSize:15];
    self.title.textColor = [UIColor grayColor];
    
    [self.contentView addSubview:self.title];
    
#pragma mark userImageView
    CGFloat height = self.title.frame.origin.y + self.title.frame.size.height;
    self.userImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, height, 25, 25)];
    self.userImageView.layer.cornerRadius = self.userImageView.frame.size.width / 2;
    self.userImageView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.userImageView];
    
#pragma mark userName
    self.userName = [[UILabel alloc] initWithFrame:CGRectMake(50, height, self.contentView.frame.size.width - 20, 25)];
    self.userName.textColor = [UIColor colorWithWhite:0.671 alpha:1.000];
    self.userName.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.userName];
    
}

- (void)setTypeTen:(TypeTen *)typeTen {
    
    _typeTen = typeTen;
    
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"states"] isEqualToString:@"1"]) {
        self.contentView.backgroundColor = [UIColor colorWithRed:0.18 green:0.21 blue:0.24 alpha:1];
    }
    else {
        
        self.contentView.backgroundColor = [UIColor whiteColor];
    }
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:self.typeTen.index_cover]];
    self.title.text = [self.typeTen index_title];
    [self.userImageView sd_setImageWithURL:[NSURL URLWithString:self.typeTen.users.avatar_m] placeholderImage:[UIImage imageNamed:@"avatar_placeholder_26"]];
    self.userName.text = [[self.typeTen users] name];
    
}

@end
